package com.xtsoft.platform.base.system.domain;

/*
*    上海信拓信息技术有限公司  
*    Copyright (C) ShangHai XinTuo Software Inc.
*/

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.xtsoft.core.entity.GenericEntity;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;

import jakarta.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 * SysRole Base Java Bean, base class for the model, mapped directly to database table
 * 
 * Avoid changing this file if not necessary, will be overwritten. 
 *
 * 角色表
 */
@Entity
@Table(name = "sys_role")
@Data
//@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class SysRole extends GenericEntity {


	@Id
	@GeneratedValue(generator = "system-uuid")
	@GenericGenerator(name = "system-uuid", strategy = "uuid")
	@Column(name="roleId",nullable=false,length=32)
    private String roleId;




	/**
	*   角色名称
	*/
	@Column(name="roleName",nullable=false, length=128 )
	private String roleName;


	/**
	*   别名
	*/
	@Column(name="alias",nullable=false, unique=true,length=128 )
	private String alias;


	/**
	*   角色级别
	*/
	@Column(name="roleLevel",nullable=true, length=10 )
	private Integer roleLevel;


	/**
	*   状态
	*/
	@Column(name="state",nullable=true, length=10 )
	private Integer state;


	/**
	*   说明
	*/
	@Column(name="descript",nullable=true, length=255 )
	private String descript;



	@OneToMany(mappedBy = "sysRole", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JsonIgnore
	private List<UserRole> userRoles = new ArrayList();
	
	
	@OneToMany(mappedBy = "sysRole", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JsonIgnore
	private List<ResourceRole> resourceRoles = new ArrayList();                                                      
	                                                                                                                      
	//mappedBy表明ONE方放弃关系维护，这是正确的,适用于大多数场景
	//orphanRemoval=true, 移走孤儿，表明不允许一方的多方有空记录
	@OneToMany(mappedBy = "sysRole", cascade=CascadeType.ALL, fetch = FetchType.LAZY)   
	@JsonIgnore
	private List<DashboardRole> dashboardRoles = new ArrayList();
	
	/**
	 * 默认构造
	 */
	public SysRole(){
		//code auto generate
	}
	
	/**
	*  构造方法，自动测试使用，把除主键外的所有非空字段赋值
	*
	*  也可作普通使用  调用该构造方法时，字串参数填或不填均
	*  可，该带参构造方法仅为区别Lombok自动生成的默认构造方
	*  法。
	*  
	*  应用程序可根据需要修改该构造方法中的非空属性赋值。
	**/
	public SysRole(String forAutoTest){

		this.roleName = "New string";


		this.alias = "New string";

	}

	@Override  
	public boolean equals(Object obj) {  
	    if (obj instanceof SysRole) {  
	        return this.roleId.equals(((SysRole) obj).getRoleId());  
	    }  
	    return false;  
	}  	

	@Override  
	public int hashCode() {  
	    return this.roleId.hashCode();  
	} 	
}
